package com.pointstar.dp.modules.project.controller;

import java.util.Map;

import com.pointstar.dp.modules.project.entity.dto.InOutBoundDTO;
import com.pointstar.dp.modules.project.entity.ro.SaveOutBoundRo;
import com.pointstar.dp.modules.project.service.OutBoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pointstar.dp.common.annotation.SysLog;
import com.pointstar.dp.modules.sys.controller.AbstractController;
import com.pointstar.dp.common.entity.Page;
import com.pointstar.dp.common.entity.R;
import com.pointstar.dp.modules.project.entity.OutBoundEntity;

/**
 * 出库主表
 * @author Korey<m13057531285@163.com>
 */
@RestController
@RequestMapping("/outbound")
public class OutBoundController extends AbstractController {
	
	private final OutBoundService outBoundService;


	@Autowired
	public OutBoundController(OutBoundService outBoundService) {
		this.outBoundService = outBoundService;
	}

	/**
	 * 查询出库主表列表
	 *
	 * @param params 查询参数
	 * @return 出库主表列表
	 */
	@PostMapping("/list")
	public Page<OutBoundEntity> list(@RequestBody Map<String, Object> params) {
		return outBoundService.listOutBound(params);
	}
		
	/**
	 * 新增
	 *
	 * @param outBound 出库主表实体类
	 * @return 结果
	 */
	@SysLog("新增出库主表")
	@PostMapping("/save")
	public R save(@RequestBody OutBoundEntity outBound) {
		return outBoundService.saveOutBound(outBound);
	}

	/**
	 * 商品出库
	 *
	 * @param saveOutBoundRo
	 * @return 结果
	 */
	@SysLog("新增出库主表及明细表")
	@PostMapping("/saveOutBoundAndDetails")
	public R saveOutBoundAndDetails(@RequestBody SaveOutBoundRo saveOutBoundRo) {
		return outBoundService.saveOutBoundAndDetails(saveOutBoundRo);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	@PostMapping("/info")
	public R getById(@RequestBody Long id) {
		return outBoundService.getOutBoundById(id);
	}
	
	/**
	 * 修改
	 * @param outBound
	 * @return
	 */
	@SysLog("修改出库主表")
	@PostMapping("/update")
	public R update(@RequestBody OutBoundEntity outBound) {
		return outBoundService.updateOutBound(outBound);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@SysLog("删除出库主表")
	@PostMapping("/remove")
	public R batchRemove(@RequestBody Long[] id) {

		//return outBoundService.batchRemove(id);

		//1、主表更新删除标志和插入负记录
		//2、明细表更新删除标志
		//3、恢复入库库存
		return outBoundService.batchRemoveLogic(id);
	}


	
}
